﻿//------------------------------------------------------------------------------
// ╭─────────────────────────────╮
// │ ╭─╮     ╭─╮              TM │   ╠═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╣
// │ │ │     │ │                 │                                           ☺  
// │ │ ╰───╮ │ │ ╭─────╮ ╭─────╮ │     Name:Wedn.Net HttpModule        ♮ ♪ ♩
// │ │ ╭─╮ │ │ │ │ ╭─╮ │ │ ╭─╮ │ │                                    ♫ ♭      
// │ │ ╰─╯ │ │ │ │ ╰─╯ │ │ ╰─╯ │ │     Author:iceStone               ♬ ♪       
// │ └─────╯ └─╯ ╰─────╯ ╰───╮ │ │     Chinese:汪磊                              
// │                     ┌───╯ │ │                                              
// │                     ╰─────╯ │   ╠═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╣
// ╰─────────────────────────────╯                                              
//------------------------------------------------------------------------------
using System;
using System.Runtime.Remoting.Messaging;
using System.Web;

namespace Wedn.Net.UI.Module
{
    /// <summary>
    /// HttpModule类
    /// </summary>
    public class HttpModule : IHttpModule
    {
        /// <summary>
        /// 释放
        /// </summary>
        public void Dispose()
        {
            //throw new NotImplementedException();
        }
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="application"></param>
        public void Init(HttpApplication application)
        {
            application.BeginRequest += Application_BeginRequest;
            //application.Error += Application_Error;
        }
        /// <summary>
        /// 响应开始事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Application_BeginRequest(object sender, EventArgs e)
        {
            Common.Statistics.Instance.StartTime = DateTime.Now;
            Common.Statistics.Instance.QueryCount = 0;
        }
        ///// <summary>
        ///// 应用程序错误事件
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //private void Application_Error(object sender, EventArgs e)
        //{
        //    Exception ex = ((HttpApplication)sender).Server.GetLastError();
        //    if (ex.GetType().Name == "HttpException")
        //    {
        //        var exception = (HttpException)ex;
        //        if (exception.GetHttpCode() == 404)
        //        {
        //            HttpContext context = HttpContext.Current;
        //            context.Response.Clear();
        //            context.Response.StatusCode = 404;
        //            context.Response.WriteFile(context.Server.MapPath("/views/shared/404.html"));
        //            context.Response.End();
        //        }
        //    }
        //}

        //void Application_EndRequest(object sender, EventArgs e)
        //{
        //    //var dbContext = CallContext.GetData("CurrentDbContext") as System.Data.Entity.DbContext;
        //    //if (dbContext != null)
        //    //{
        //    //    dbContext.Dispose();
        //    //}
        //}
    }
}
